package dao;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import entity.Comments;
import util.DBUtil;

public class CommentsDao {
	//删除了不必要的一行
	//增加评论
	public Integer add(Comments c){
		String sql="insert into comments (cnid,ccontent,cdate,cip,cauthor) values (?,?,?,?,?)";
		Integer i=DBUtil.executeUpdate(sql,c.getCnid(),c.getCcontent(),sd.format(c.getCdate()),c.getCip(),c.getCauthor());
		return i;
	}
	
	//根据新闻查找评论
	public List<Comments> findComments(Long cnid){
		String sql="select * from comments  where cnid=? order by cdate desc";
		List<Comments> list=DBUtil.query(sql, Comments.class,cnid);
		return list;
	}
	
	//删除评论
	public Integer delComment(Integer cid){
		String sql="delete from comments where cid=?";
		Integer i=DBUtil.executeUpdate(sql,cid);
		return i;
		
	}
	
	
	public static void main(String[] args) {
		CommentsDao cdao=new CommentsDao();
		/*Comments c=new Comments(50L,"aaa",new Date(),"1212","dsas");
		Integer i=cdao.add(c);
		System.out.println(i);*/
		/*List<Comments> list=cdao.findComments(186);
		for(Comments c:list){
			System.out.println(c);
		}*/
	}

}
